import java.io.*;
import java.io.Console;
import java.util.regex.*;
class CompilerLittleHelper{
	
		/*Uso queste variabili statiche per non dover ripartire da 0 ogni volta*/
		static File parsedFile=null;
		static int linesParsed=0;
		static int result=0;
		static boolean inside=false;
		static FileInputStream stream=null;
		static BufferedReader reader=null;
		
		
		static String linesAt(File file, int lines) throws Exception{
			if (parsedFile==null || lines<linesParsed) {
				parsedFile=file;
				if (stream!=null) stream.close();
				stream= new FileInputStream(parsedFile);
				if (reader!=null) reader.close();
				reader= new BufferedReader(new InputStreamReader(stream));
				inside=false;
				result=0;
				linesParsed=0;
			}			
			String line=null;						
			while(linesParsed<lines){
				linesParsed++;
				line= reader.readLine();		
				if (line.startsWith("/**BEGIN** Added byJavaRoleParser:")) inside=true;
				if (!inside) result++;
				if (line.startsWith("Addition by JavaRoleParser: **END**/")) inside=false;				
			}
			
			if (inside) return "added by parser, please inform developers";		
			return Integer.toString(result);			
		}
		
		
		static void help(File compilationResult, String fileCompiled){
			//useful when compiling errors occur			
			try{
				File compiled = new File(fileCompiled);
				FileInputStream stream= new FileInputStream(compilationResult);
				BufferedReader reader= new BufferedReader(new InputStreamReader(stream));
				String line;
				int oldLine=0;
				while((line=reader.readLine())!=null){					
					if(line.startsWith(fileCompiled+":")){						
						int dotindex=line.indexOf(':')+1;						
						System.err.print(line);
						//finding line number
						String n= "\\d+";				
						Pattern pattern = Pattern.compile(n);
						Matcher match = pattern.matcher(line.substring(dotindex));
						if (match.find()){
							oldLine = Integer.parseInt(match.group());							
						}else throw new Exception();							
						System.err.println(" [Original line: "+linesAt(compiled, oldLine)+"]");
					}
					else System.err.println(line);					
				}
			}catch(Exception e){
				e.printStackTrace();
				return;
			}		
			return ;
		}	
	
	
	
	
	
}
